package com.mjk.api;


import com.mjk.api.dto.ApiDto;
import com.mjk.common.base.error.BeeError;
import com.mjk.common.base.response.BeeResponse;
import com.mjk.common.base.work.BaseWork;
import com.mjk.common.base.work.annotation.BeeApi;
import com.mjk.common.base.work.annotation.BeeWork;
import com.mjk.common.core.jdbc.bean.BeePage;
import com.mjk.common.core.jdbc.service.log.model.BeeLogModel;
import com.mjk.common.core.jdbc.service.plus.idbservice.BeeDBService;
import com.mjk.common.core.jdbc.service.plus.wrap.BeeQueryWrapper;
import com.mjk.common.tools.xml.XmlUtils;
import com.mjk.common.util.TimeUtils;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.Date;


@BeeWork(work = "api")
public class TestWork extends BaseWork {

    @Autowired
    private BeeDBService beeDBService;


    @BeeApi(type = BeeApi.ResponseType.JSON)
    public BeeResponse getApiTest(ApiDto dto){
        BeeQueryWrapper wrapper = new BeeQueryWrapper(new BeeLogModel(),dto);

        wrapper.between(BeeLogModel::getCreateTime, TimeUtils.parse(TimeUtils.DATE_FORMAT_DATETIME,"2024-07-03 00:00:00"),
                TimeUtils.getDayEnd(new Date()));
        wrapper.setPage(1, 10);
        BeePage<BeeLogModel> list = beeDBService.findManyByWrapperWithPage(wrapper);
        return BeeError.BEE_SUC.tranceError(list);
    }

    /**
     * 错误 会返回一个调用的堆栈信息
     */
    public BeeResponse getApiTestError(ApiDto dto){
        XmlUtils.xmlToBean("<root/>", ApiDto.class);
        return BeeError.BEE_FAILD.tranceError();
    }

}
